%%
clc;clear
syms p(n) z Ts T s f zz
assume(n>0 & in(n,'integer'))
assume(T>0)
assume(Ts>0)

%% s domain to z domain
fs = 1/(T*s+1)
s_ = (1-z^-1)/Ts
fz = subs(fs, s, s_)
fz = collect(expand(fz),z^-1)

%% z domain to difference equations
syms x y
assume(T ~= T*z + Ts*z)
equ = y == fz*x
equ = simplify(equ)
equ = expand(equ)

syms yn xn yn_s1 xn_s1
equ_tmp = subs(equ, y/z, yn_s1)
equ_tmp = subs(equ_tmp, y, yn)
equ_tmp = subs(equ_tmp, x, xn)
yn = solve(equ_tmp, yn)
yn = collect(yn,[xn,yn_s1])

